-- Copyright (C) 2016 Koz Ross <koz.ross@retro-freedom.nz>

-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.

-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.

-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.

import BasicPrelude hiding (empty)

import Data.Logic.DNF

import Criterion.Main

import Test.QuickCheck

main :: IO ()
main = do
  let sizes = [10, 20 .. 50]
  let names = fmap (textToString . ("b" ++) . show) sizes
  testData <- generate $ traverse (\x -> resize x arbitrary :: Gen Form) sizes
  testForms <- generate $ traverse (\x -> resize x arbitrary :: Gen Interpretation) sizes
  let named = zip names testData
  let interpreted = zip3 names testForms testData
  let optimized = zip3 names testForms (optimize <$> testData)
  defaultMain [
    bgroup "raw_interpret" ((\(s, i, f) -> bench s (whnf (interpret i) f)) <$> interpreted),
    bgroup "safe_raw_interpret" ((\(s, i, f) -> bench s (whnf (interpretSafe i) f)) <$> interpreted),
    bgroup "optimizer" ((\(s, f) -> bench s (whnf optimize f)) <$> named),
    bgroup "opt_interpret" ((\(s, i, f) -> bench s (whnf (interpret i <$>) f)) <$> optimized),
    bgroup "safe_opt_interpret" ((\(s, i, f) -> bench s (whnf (interpret i <$>) f)) <$> optimized)
    ]
